<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html lang="zh-CN">
   <head>
	 <meta charset="utf-8">
	 <meta http-equiv="X-UA-Compatible" content="IE=edge">
	 <meta name="viewport" content="width=device-width, initial-scale=1">
   </head>
   <body>
	<div class="modal-content">
	  <div class="modal-header">
	    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	    <h4 class="modal-title" id="myModalLabel"><c:if test="${type==1}">新增</c:if><c:if test="${type==2}">编辑</c:if></h4>
	  </div>
	  <div class="modal-body">
	
	    <form id="objectForm" class="form-horizontal" method="post">
	    
<%-- 	      <div class="form-group">

	        <label for="divisionName" class="col-sm-2 control-label"><span style="color:red;"> * </span>所属地区</label>
	        <div class="col-sm-6">
	          <select class="form-control" name="sysDivision[id]">
		         <c:forEach items="${divisionList}" var ="division">
		             	 <option value="${division.id}">${division.name}</option>
		         </c:forEach>
		      </select> 
	        </div>
	      </div>  --%>
	      
	      <div class="form-group">
	         <label for="divisionName" class="col-sm-2 control-label"><span style="color:red;"> * </span>所属地区</label>
	         <div class="col-sm-6">
	         	<input id="citySel" class="form-control" type="text" value="${project.sysDivision.name}" name="sysDivision[id]" onclick="showMenu(); return false;" readonly/>
	         	<div id="menuContent" class="menuContent" style="display:none;">
					<ul id="ztree" class="ztree"></ul>
				</div>
	      	 </div>
	      </div> 
	      
	      <div class="form-group">
	      	<input type="hidden" name="id" value="${project.id}"/>
	        <input type="hidden" class="typeCode" value="${type}"/>
	        <label for="name" class="col-sm-2 control-label"><span style="color:red;"> * </span>名称</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="name" name="name" value="${project.name}">
	        </div>
	      </div> 
	      
	      <div class="form-group">
	        <label for="ccProjectCode" class="col-sm-2 control-label"><span style="color:red;"> * </span>中海项目编码</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="ccProjectCode" name="ccProjectCode" value="${project.ccProjectCode}">
	        </div>
	      </div>  
	      
	      <div class="form-group">
	        <label for="entranceCode" class="col-sm-2 control-label"><span style="color:red;"> * </span>迈斯项目编码</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="entranceCode" name="entranceCode" value="${project.entranceCode}">
	        </div>
	      </div>  
	      
	      <div class="form-group">
	        <label for="code" class="col-sm-2 control-label"><span style="color:red;"> * </span>机房远程监控编码</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="code" name="code" value="${project.code}">
	        </div>
	      </div>  
	      
	      <div class="form-group">
	        <label for="patrolCode" class="col-sm-2 control-label"><span style="color:red;"> * </span>巡更项目编码</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="patrolCode" name="patrolCode" value="${project.patrolCode}">
	        </div>
	      </div>  
	      
	      <div class="form-group">
	        <label for="parkingCode" class="col-sm-2 control-label"><span style="color:red;"> * </span>停车场项目编码</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="parkingCode" name="parkingCode" value="${project.parkingCode}">
	        </div>
	      </div>  
	      
	      <div class="form-group">
	        <label for="longitude" class="col-sm-2 control-label">经度</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="longitude" name="longitude" value="${project.longitude}">
	        </div>
	      </div>   
	      
	      <div class="form-group">
	        <label for="latitude" class="col-sm-2 control-label">纬度</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="latitude" name="latitude" value="${project.latitude}">
	        </div>
	      </div> 
	      
	    </form>
	  </div>
	  <div class="modal-footer">
	  <div class="form-group">
	    <button type="button" class="btn btn-info btn-white btn-round" onclick="objectSubmit();"> <i class="glyphicon glyphicon-ok bigger-125"></i> 确认</button>
	    <button type="button" class="btn btn-default btn-white btn-round" data-dismiss="modal"><i class="glyphicon glyphicon-remove bigger-125"></i> 取消</button>
	  </div>
	  </div>
	</div>
	
	<script>
	 var path = "<%=path%>";
 	 function objectSubmit(){  
 	 	var url= null;
 	 	var type = $('.typeCode').val();
		if(type==1){//添加实体
			url = path + "/projectController/new";
		}else{//编辑实体
			url = path + "/projectController/edit";
		}
     	$.ajax({
		  type: "post",
		  url: url,
		  async:false,
		  data: JSON.stringify($('#objectForm').serializeObject()),
		  dataType: "json",
		  contentType:"application/json",  
		  success: function(result){
		         if(result.status){        	 
		        		$.toast({
		        		    text: result.message,
		        		    hideAfter : 1500,  
		        		    stack : 1,  
		        		    showHideTransition: 'slide',
		        		    icon: 'success',
		        		    textAlign : 'center',
		        		    position : 'top-right'
		        		})
		        	   $('#objectForm').parents('.modal').modal('hide');
		        	   $table.bootstrapTable('refresh');
		         }else{
		        	 $.toast({
		        		    text: result.message,
		        		    hideAfter : 1500,  
		        		    stack : 1,  
		        		    showHideTransition: 'slide',
		        		    icon: 'error',
		        		    textAlign : 'center',
		        		    position : 'top-right'
		        		})
		         }
		  }
         });
      } 
 	 
 	/******************************** 树形菜单 ****************************************/	     
     var path = "<%=path%>";
		var setting = {
				async: {
					enable: true,
					url: path+"/divisionController/getDivisionZTree",
					autoParam:["id", "name=n", "level=lv"],
					otherParam:{"otherParam":"zTreeAsyncTest"},
					dataFilter: filter
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				view: {
					dblClickExpand: false,
					selectedMulti: false
				},
				callback: {
					beforeClick: beforeClick,
					onClick: onClick
				}
			};

			function filter(treeId, parentNode, childNodes) {
				if (!childNodes) return null;
				for (var i=0, l=childNodes.length; i<l; i++) {
					childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
				}
				return childNodes;
			}
			function beforeClick(treeId, treeNode) {
				var check = (treeNode && !treeNode.isParent);
				if (!check) alert("只能选择城市...");
				return check;
			}
			
			function onClick(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("ztree"),
				nodes = zTree.getSelectedNodes(),
				name = "";
				nodes.sort(function compare(a,b){return a.id-b.id;});
				for (var i=0, l=nodes.length; i<l; i++) {
					name += nodes[i].id + ",";
				}
				if (name.length > 0 ) name = name.substring(0, name.length-1);
				var cityObj = $("#citySel");
				cityObj.attr("value", name);
			}

			function showMenu() {
				var cityObj = $("#citySel");
				var cityOffset = $("#citySel").offset();
				$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

				$("body").bind("mousedown", onBodyDown);
			}
			function hideMenu() {
				$("#menuContent").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDown);
			}
			function onBodyDown(event) {
				if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
					hideMenu();
				}
			}
			
			$(document).ready(function(){
				$.fn.zTree.init($("#ztree"), setting);
			});
			
	/******************************** 树形菜单  end ***********************************/		
	</script>
	</body>
</html>
